<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon.ico?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon.ico?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="JavaScript,">










<meta name="description" content="Array类型1.类型检测 instanceof 和 isArray()  instanceof运算符用于检测构造函数的 prototype 属性是否出现在某个实例对象的原型链   Array.isArray()用于检测一个数据类型是否为数组 12var arr = [1,2,3]Array.isArray(arr) // true      延伸：typeof和instanceof的区别 相同点">
<meta name="keywords" content="JavaScript">
<meta property="og:type" content="article">
<meta property="og:title" content="js数组">
<meta property="og:url" content="http://zhanglei_c.gitee.io/blog/2019/10/15/js数组/index.html">
<meta property="og:site_name" content="爱吃零食的猫">
<meta property="og:description" content="Array类型1.类型检测 instanceof 和 isArray()  instanceof运算符用于检测构造函数的 prototype 属性是否出现在某个实例对象的原型链   Array.isArray()用于检测一个数据类型是否为数组 12var arr = [1,2,3]Array.isArray(arr) // true      延伸：typeof和instanceof的区别 相同点">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-10-30T06:16:57.835Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="js数组">
<meta name="twitter:description" content="Array类型1.类型检测 instanceof 和 isArray()  instanceof运算符用于检测构造函数的 prototype 属性是否出现在某个实例对象的原型链   Array.isArray()用于检测一个数据类型是否为数组 12var arr = [1,2,3]Array.isArray(arr) // true      延伸：typeof和instanceof的区别 相同点">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://zhanglei_c.gitee.io/blog/2019/10/15/js数组/">





  <title>js数组 | 爱吃零食的猫</title>
  








</head>

<script type="text/javascript" color="0,0,255" opacity="0.7" zindex="-2" count="99" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/403NotFound" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">爱吃零食的猫</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">自由，平等，公正，法治</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://zhanglei_c.gitee.io/blog/blog/2019/10/15/js数组/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Zhang_lei">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱吃零食的猫">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">js数组</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-10-15T00:14:38+08:00">
                2019-10-15
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="Array类型"><a href="#Array类型" class="headerlink" title="Array类型"></a>Array类型</h2><h4 id="1-类型检测"><a href="#1-类型检测" class="headerlink" title="1.类型检测"></a>1.类型检测</h4><ul>
<li><p><code>instanceof</code> 和 <code>isArray()</code></p>
<ul>
<li><p><code>instanceof</code><strong>运算符</strong>用于检测构造函数的 <code>prototype</code> 属性是否出现在某个实例对象的原型链 </p>
</li>
<li><p><code>Array.isArray()</code>用于检测一个数据类型是否为数组</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line"><span class="built_in">Array</span>.isArray(arr) <span class="comment">// true</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
</ul>
<blockquote>
<p>延伸：<strong><code>typeof</code>和<code>instanceof</code>的区别</strong></p>
<p>相同点：都常用来判断一个变量是否为空，或者是什么类型的 </p>
<ul>
<li><p><code>typeof</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&gt;   <span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">&gt;   <span class="keyword">typeof</span>(arr) <span class="comment">// Object</span></span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>
</blockquote>
<blockquote>
<ul>
<li><code>typeof</code>的返回值是一个字符串，他能检测 <code>Number</code>，<code>String</code>，<code>Boolean</code>, <code>function</code>, <code>Object</code>, <code>Undefined</code>, <code>Symbol</code>等类型</li>
<li>对于<code>Null</code>，<code>Array</code>等特殊对象<code>typeof</code>均返回 <code>Object</code>,这也是<code>typeof</code>的局限性所在</li>
</ul>
<ul>
<li><p><code>instanceof</code></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&gt;   <span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">&gt;   <span class="built_in">console</span>.log(arr <span class="keyword">instanceof</span> <span class="built_in">Array</span>) <span class="comment">// true</span></span><br><span class="line">&gt;</span><br></pre></td></tr></table></figure>
</li>
</ul>
</blockquote>
<blockquote>
<ul>
<li>用于判断一个变量是否属于一个对象的实例</li>
<li>返回值是一个布尔值</li>
<li>可以用来检测<code>Null</code>和<code>Array</code></li>
</ul>
</blockquote>
<h4 id="2-方法"><a href="#2-方法" class="headerlink" title="2.方法"></a>2.方法</h4><h5 id="2-1转换方法"><a href="#2-1转换方法" class="headerlink" title="2.1转换方法"></a>2.1转换方法</h5><ul>
<li><code>toString()</code>返回数组中每一项由逗号连接的字符串</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line"><span class="built_in">console</span>.log(arr.toString()) <span class="comment">// "1,2,3"</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>valueOf()</code>返回数组对象本身</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">arr.toString() <span class="comment">// "1,2,3"</span></span><br><span class="line">arr.valueOf() <span class="comment">// [1,2,3]</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>toLocaleString</code> 返回调用 <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString" target="_blank" rel="noopener"><code>toString()</code></a> 的结果。 </li>
</ul>
<h5 id="2-2-栈方法（LIFO）"><a href="#2-2-栈方法（LIFO）" class="headerlink" title="2.2 栈方法（LIFO）"></a>2.2 栈方法（LIFO）</h5><ul>
<li>push() 入栈</li>
<li>pop() 出栈(移除数组最后一项)</li>
</ul>
<h5 id="2-3-队列方法-FIFO"><a href="#2-3-队列方法-FIFO" class="headerlink" title="2.3 队列方法(FIFO)"></a>2.3 队列方法(FIFO)</h5><ul>
<li>push() 入队列</li>
<li>shift() 出队列（移除数组第一项）</li>
<li>unshift() 在数组前端添加元素</li>
</ul>
<h5 id="2-4排序"><a href="#2-4排序" class="headerlink" title="2.4排序"></a>2.4排序</h5><ul>
<li>reverse() 反转数组</li>
<li>sort() 排序 由小到大</li>
</ul>
<blockquote>
<p>reverse() 和 sort() 返回值是经过排序后的数组</p>
</blockquote>
<h5 id="2-5操作方法"><a href="#2-5操作方法" class="headerlink" title="2.5操作方法"></a>2.5操作方法</h5><ul>
<li><p>concat() <strong>不影响原数组</strong></p>
<ul>
<li><p>无参数</p>
<ul>
<li>复制当前数组并返回</li>
</ul>
</li>
<li><p>有参数</p>
<ul>
<li>在当前数组的基础上，添加参数的新内容</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="string">'red'</span>,<span class="string">'green'</span>]</span><br><span class="line">arr.concat(<span class="string">'yellow'</span>,<span class="string">'pink'</span>)</span><br><span class="line">arr <span class="comment">// ['red','green','yellow','pink']</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>slice() <strong>不影响原数组</strong></p>
<ul>
<li><p>一个参数</p>
<ul>
<li>返回当前位置到数组末尾的所有项</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line"><span class="keyword">let</span> newArr = arr.slice(<span class="number">1</span>)</span><br><span class="line">newArr <span class="comment">//[2,3]</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>两个参数</p>
<ul>
<li>返回这两个参数间的所有元素</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>]</span><br><span class="line">arr.slice(<span class="number">1</span>,<span class="number">2</span>) <span class="comment">// [2,3]</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>若参数中有负数，则用数组的长度来加上这个负数来确定位置</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>,<span class="number">5</span>] <span class="comment">// length = 5</span></span><br><span class="line">arr.slice(<span class="number">-2</span>,<span class="number">-1</span>) <span class="comment">// 相当于arr.slice(3,4)</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>splice() <strong>会修改原数组</strong></p>
<ul>
<li><p>删除</p>
<ul>
<li>splice(a,b)  删除第 a 项的位置，删b 个元素,返回删除的数据</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line"><span class="keyword">var</span> del = arr.splice(<span class="number">0</span>,<span class="number">2</span>) <span class="comment">// del == [1,2], arr == [3]</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>插入</p>
<ul>
<li>splice(a,0,val)  删除第 a 项元素位置，删0 个元素，并插入 val,由于是删除0个元素，所以相当于插入元素</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">arr.splice(<span class="number">2</span>,<span class="number">0</span>,<span class="number">4</span>) <span class="comment">// arr [1,2,4,3]</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>替换</p>
<ul>
<li>splice(a,1,val) 删除第 a 个位置的元素并插入一个新元素 val ,相当于替换了 a</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">arr.splice(<span class="number">0</span>,<span class="number">1</span>,<span class="number">4</span>) <span class="comment">// arr [4,2,3]</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>splice() 始终返回一个数组</p>
</li>
</ul>
</li>
</ul>
<h5 id="2-6位置方法"><a href="#2-6位置方法" class="headerlink" title="2.6位置方法"></a>2.6位置方法</h5><ul>
<li>indexOf()<ul>
<li>从开头开始寻找</li>
</ul>
</li>
<li>lastIndexOf()<ul>
<li>从结尾开始寻找</li>
</ul>
</li>
</ul>
<h5 id="2-7迭代方法"><a href="#2-7迭代方法" class="headerlink" title="2.7迭代方法"></a>2.7迭代方法</h5><ul>
<li><p>every()</p>
<ul>
<li>对数组中每一项运行给定函数，若每项返回值都是true,则返回true</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// every 中函数默认可以传三个参数 第一个是当前元素，第二个是当前元素的索引，第三个是当前元素所属数组</span></span><br><span class="line"><span class="keyword">let</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">arr.every((item,index,arr) &#123;</span><br><span class="line">	<span class="comment">// 操作        </span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ul>
<li><p>filter()</p>
<ul>
<li>对数组中每一项运行给定函数，只返回返回值为true的元素</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// filter 中函数默认可以传三个参数 第一个是当前元素，第二个是当前元素的索引，第三个是当前元素所属数组</span></span><br><span class="line"><span class="keyword">let</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">arr.filter((item,index,arr) &#123;</span><br><span class="line">	<span class="comment">// 操作        </span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ul>
<li><p>forEach()</p>
<ul>
<li>对数组中每一项运行给定函数，无返回值，用于遍历数组</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// forEach 中函数默认可以传三个参数 第一个是当前元素，第二个是当前元素的索引，第三个是当前元素所属数组</span></span><br><span class="line"><span class="keyword">let</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">arr.forEach((item,index,arr) &#123;</span><br><span class="line">	<span class="comment">// 操作            </span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ul>
<li><p>map()</p>
<ul>
<li>对数组中每一项运行给定函数，返回函数调用过后的新数组</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// map 中函数默认可以传三个参数 第一个是当前元素，第二个是当前元素的索引，第三个是当前元素所属数组</span></span><br><span class="line"><span class="keyword">let</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">arr.map((item,index,arr) &#123;</span><br><span class="line">	<span class="comment">// 操作        </span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<ul>
<li><p>some()</p>
<ul>
<li>对数组中每一项运行给定函数，只要任意一项返回true,则返回值为true</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// some 中函数默认可以传三个参数 第一个是当前元素，第二个是当前元素的索引，第三个是当前元素所属数组</span></span><br><span class="line"><span class="keyword">let</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>]</span><br><span class="line">arr.some((item,index,arr) &#123;</span><br><span class="line">	<span class="comment">// 操作        </span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
</li>
</ul>
<h5 id="2-7归并方法"><a href="#2-7归并方法" class="headerlink" title="2.7归并方法"></a>2.7归并方法</h5><ul>
<li><p>reduce() 从第一项开始</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 求数组中所有项的和</span></span><br><span class="line"><span class="keyword">var</span> arr = [<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">4</span>]</span><br><span class="line"><span class="keyword">var</span> sum = arr.reduce(<span class="function"><span class="keyword">function</span>(<span class="params">prev,cur,index,array</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> prev + cur;</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">// 函数的返回值会作为参数传入下一项</span></span><br><span class="line">prev    cur</span><br><span class="line"><span class="number">1</span>	<span class="number">2</span></span><br><span class="line"><span class="number">3</span>	<span class="number">3</span></span><br><span class="line"><span class="number">6</span>	<span class="number">4</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<ul>
<li>reduceRight() 从最后一项开始</li>
</ul>
<h3 id="方法汇总"><a href="#方法汇总" class="headerlink" title="方法汇总"></a>方法汇总</h3><ol>
<li>concat()</li>
</ol>
<ul>
<li>连接两个或多个数组</li>
<li><strong>不改变原数组</strong></li>
<li>返回被连接数组的一个副本</li>
</ul>
<ol start="2">
<li>join()</li>
</ol>
<ul>
<li>把数组中所有元素放入一个字符串</li>
<li><strong>不改变元素组</strong></li>
<li>返回一个字符串</li>
</ul>
<ol start="3">
<li>slice()</li>
</ol>
<ul>
<li>从已有数组中返回选定的元素</li>
<li><strong>不改变原数组</strong></li>
<li>返回一个新数组</li>
</ul>
<ol start="4">
<li>toString()</li>
</ol>
<ul>
<li>把数组变为字符串</li>
<li><strong>不改变原数组</strong></li>
<li>返回数组的字符串形式</li>
</ul>
<hr>
<ol start="5">
<li>pop()</li>
</ol>
<ul>
<li>删除数组的最后一个元素，如果数组为空，则不改变数组，返回undefined</li>
<li><strong>改变原数组</strong></li>
<li>返回被删除的元素</li>
</ul>
<ol start="6">
<li>push()</li>
</ol>
<ul>
<li>向数组末尾添加一个或多个元素</li>
<li><strong>改变原数组</strong></li>
<li>返回新数组的长度</li>
</ul>
<ol start="7">
<li>reserve()</li>
</ol>
<ul>
<li>反转数组中的元素</li>
<li><strong>改变原数组</strong></li>
<li>返回该数组</li>
</ul>
<ol start="8">
<li>shift()</li>
</ol>
<ul>
<li>删除数组第一个元素，若为空数组，则不进行任何操作，返回undefined</li>
<li><strong>改变原数组</strong></li>
<li>返回第一个元素的值</li>
</ul>
<ol start="9">
<li>sort()</li>
</ol>
<ul>
<li>对元素进行排序（ASCII）</li>
<li><strong>改变原数组</strong></li>
<li>返回该数组</li>
</ul>
<ol start="10">
<li>splice()</li>
</ol>
<ul>
<li>从数组中添加\删除元素</li>
<li><strong>改变原数组</strong></li>
<li>返回被删除的元素</li>
</ul>
<ol start="11">
<li>unshift()</li>
</ol>
<ul>
<li>向数组的开头添加或删除一个或对个元素</li>
<li><strong>改变原数组</strong></li>
<li>返回新数组的长度</li>
</ul>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/JavaScript/" rel="tag"># JavaScript</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2019/10/14/Hexo和Git配置/" rel="next" title="Hexo和Git配置">
                <i class="fa fa-chevron-left"></i> Hexo和Git配置
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2019/10/15/一些引用类型/" rel="prev" title="一些引用类型">
                一些引用类型 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Zhang_lei</p>
              <p class="site-description motion-element" itemprop="description">爱吃零食的猫</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">43</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">22</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/403NotFound" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://www.zhihu.com/people/ai-chi-bao-mi-hua-de-mao/activities" target="_blank" title="知乎">
                      
                        <i class="fa fa-fw fa-send"></i>知乎</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://gitee.com/ZhangLei_c" target="_blank" title="码云">
                      
                        <i class="fa fa-fw fa-github-alt"></i>码云</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://weibo.com/5205419998/profile?rightmod=1&wvr=6&mod=personinfo&is_all=1" target="_blank" title="weibo">
                      
                        <i class="fa fa-fw fa-weibo"></i>weibo</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#Array类型"><span class="nav-number">1.</span> <span class="nav-text">Array类型</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-类型检测"><span class="nav-number">1.0.1.</span> <span class="nav-text">1.类型检测</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-方法"><span class="nav-number">1.0.2.</span> <span class="nav-text">2.方法</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#2-1转换方法"><span class="nav-number">1.0.2.1.</span> <span class="nav-text">2.1转换方法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-2-栈方法（LIFO）"><span class="nav-number">1.0.2.2.</span> <span class="nav-text">2.2 栈方法（LIFO）</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-3-队列方法-FIFO"><span class="nav-number">1.0.2.3.</span> <span class="nav-text">2.3 队列方法(FIFO)</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-4排序"><span class="nav-number">1.0.2.4.</span> <span class="nav-text">2.4排序</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-5操作方法"><span class="nav-number">1.0.2.5.</span> <span class="nav-text">2.5操作方法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-6位置方法"><span class="nav-number">1.0.2.6.</span> <span class="nav-text">2.6位置方法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-7迭代方法"><span class="nav-number">1.0.2.7.</span> <span class="nav-text">2.7迭代方法</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2-7归并方法"><span class="nav-number">1.0.2.8.</span> <span class="nav-text">2.7归并方法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#方法汇总"><span class="nav-number">1.1.</span> <span class="nav-text">方法汇总</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Zhang_lei</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>


<div>
<span id="busuanzi_container_site_pv">
  本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<span id="busuanzi_container_site_uv">
    有<span id="busuanzi_value_site_uv"></span>人看过我的博客啦
</span>
</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
